//
//  LRSMenuViewController.swift
//  LaiLang
//
//  Created by David on 2017/2/19.
//  Copyright © 2017年 David. All rights reserved.
//

import UIKit

let LRSThemeColor1 = UIColor(hex: 0x1e2028)
let LRSThemeColor2 = UIColor(hex: 0x8f000d)



class LRSMenuViewController: UIViewController {

    override var preferredStatusBarStyle: UIStatusBarStyle{
        get{
            return .lightContent
        }
    }
    
    var loadingView: LLFullScreenLoading!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        view.backgroundColor = LRSThemeColor1
        
        let titleWhtie = UILabel(frame: CGRect(x: 0, y: 200, width: view.bounds.width, height: 20))
        titleWhtie.center.x = view.center.x
        titleWhtie.text = "天黑/请/闭眼"
        titleWhtie.textAlignment = .center
        titleWhtie.textColor = UIColor.white
        view.addSubview(titleWhtie)
        
        let titleRed = UILabel(frame: CGRect(x: 64, y: 224, width: view.bounds.width - 128, height: 20))
        titleRed.text = "IT'S GETTING DARK."
        titleRed.sizeToFit()
        titleRed.center.x = view.center.x
        titleRed.textColor = UIColor.white
        titleRed.backgroundColor = LRSThemeColor2
        titleRed.alpha = 0.6
        view.addSubview(titleRed)
        
        
        let newGameBtn = UIButton(frame: CGRect(x: 16, y: view.bounds.height - 72, width: (view.bounds.width - 32)/2 - 8, height: 64))
        newGameBtn.layer.cornerRadius = 8
        newGameBtn.layer.borderColor = UIColor.white.cgColor
        newGameBtn.layer.borderWidth = 1
        
        var str = "创建房间\n(由法官操作)"
        var attrStr = NSMutableAttributedString(string: str)
        attrStr.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 18), range: NSMakeRange(0, 4))
        attrStr.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 14), range: NSMakeRange(5, 7))
        attrStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: NSMakeRange(0, str.characters.count))
        newGameBtn.setAttributedTitle(attrStr, for: .normal)
        newGameBtn.titleLabel?.numberOfLines = 0
        newGameBtn.addTarget(self, action: #selector(LRSMenuViewController.createNewGame), for: .touchUpInside)
        
        view.addSubview(newGameBtn)
        
        let joinGameBtn = UIButton(frame: CGRect(x: view.bounds.width/2 + 8, y: view.bounds.height - 72, width: (view.bounds.width - 32)/2 - 8, height: 64))
        joinGameBtn.layer.cornerRadius = 8
        joinGameBtn.layer.borderColor = UIColor.white.cgColor
        joinGameBtn.layer.borderWidth = 1
        joinGameBtn.addTarget(self, action: #selector(LRSMenuViewController.joinGame), for: .touchUpInside)
        
        str = "加入房间\n(由玩家操作)"
        attrStr = NSMutableAttributedString(string: str)
        attrStr.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 18), range: NSMakeRange(0, 4))
        attrStr.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 14), range: NSMakeRange(5, 7))
        attrStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: NSMakeRange(0, str.characters.count))
        joinGameBtn.setAttributedTitle(attrStr, for: .normal)
        joinGameBtn.titleLabel?.numberOfLines = 0
        
        view.addSubview(joinGameBtn)
        
        let backBtn = UIButton(frame: CGRect(x: 16, y: 36, width: 24, height: 24))
        backBtn.setImage(#imageLiteral(resourceName: "navbar_back"), for: .normal)
        view.addSubview(backBtn)
        backBtn.addTarget(self, action: #selector(LRSMenuViewController.goBack), for: .touchUpInside)
        
        
    }

    
    
    func goBack(){
        _ = navigationController?.popViewController(animated: true)
    }
    
    func createNewGame(){
        hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(LRSNewViewController(), animated: true)
    }
    
    func joinGame(){
        hidesBottomBarWhenPushed = true
        
        self.navigationController?.pushViewController(LRSPlayerViewController(), animated: true)
        
//        let alert = UIAlertController(title: "请输入房间号", message: nil, preferredStyle: .alert)
//        alert.addTextField { (tf) in
//            tf.keyboardType = .numberPad
//        }
//        alert.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil))
//        alert.addAction(UIAlertAction(title: "确定", style: .default, handler: { (action) in
//            let input = alert.textFields?.first?.text
//            if input != nil{
//                self.LRSJoinGame(roomID: input!)
//                
//            }
//        }))
//        present(alert, animated: true, completion: nil)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
